﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UITesting;
using BackOffice.Context.UltiPro.BackOfficeUIMapClasses;
using BackOffice.Context.UltiPro.Controls;
using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
using Microsoft.VisualStudio.TestTools.UITest.Extension;

namespace BackOffice.Context.UltiPro.PageObjects
{
    /// <summary>
    /// View Edit screen
    /// </summary>
    public static class ViewEdit
    {
        private static BackOfficeUIMap UIMap
        {
            get
            {
                return new BackOfficeUIMap();
            }
        }

        public static SuperFinder SuperFinderWindow
        {
            get
            {
                return new SuperFinder();
            }
        }

        public static UITestControl SuperFinderPanel
        {
            get
            {
                return UIMap.UIULTIPROWindow.UICodeSetupWindow.UISuperFinder.SuperFinder;
            }
        }

        public static WinTree TreeView
        {
            get
            {
                return UIMap.UIULTIPROWindow.UICodeSetupWindow.UIViewEdit.ViewEditItemTree;
            }
        }

        public static WinTreeItem TreeItemCode(string item, string subItem = "")
        {
            WinTreeItem targetItem = null;
            WinTreeItem treeSubItem = null;

            WinTreeItem treeItem = new WinTreeItem(TreeView);
            
            #region Search Criteria
            treeItem.SearchProperties[WinTreeItem.PropertyNames.Name] = item;
            treeItem.SearchProperties["Value"] = "0";
            treeItem.WindowTitles.Add("ULTIPRO - [View/Edit Employee]");

            if (!string.IsNullOrEmpty(subItem))
            {
                treeSubItem = new WinTreeItem(treeItem);
                treeSubItem.SearchProperties[WinTreeItem.PropertyNames.Name] = "Personal";
                treeSubItem.SearchProperties["Value"] = "1";
                treeSubItem.SearchConfigurations.Add(SearchConfiguration.ExpandWhileSearching);
                treeSubItem.SearchConfigurations.Add(SearchConfiguration.NextSibling);
                treeSubItem.WindowTitles.Add("ULTIPRO - [View/Edit Employee]");
            }

            #endregion

            if (!string.IsNullOrEmpty(subItem))
                targetItem = treeSubItem;
            else
                targetItem = treeItem;

            return targetItem;
        }

        public static WinEdit MainPersonalAddress1
        {
            get 
            {
                return UIMap.UIULTIPROWindow.UICodeSetupWindow.UIViewEditMainPersonalAddressLine1.AddressLine1;
            }
        }

        public static WinEdit MainPersonalHomePhone
        {
            get
            {
                return UIMap.UIULTIPROWindow.UICodeSetupWindow.UIViewEditMainPersonalHomePhone.HomePhone;
            }
        }
    }
}
